class Dash {
  constructor(player) {
    this.player = player
  }

  setup({
    file,
    isLive
  }) {
    this.dashPlayer = window.dashjs.MediaPlayer().create()
    this.dashPlayer.initialize(this.player.dom.video, file, false)
    this.dashPlayer.enableManifestDateHeaderTimeSource(false);
    this.dashPlayer.setLiveDelayFragmentCount(0);
    this.dashPlayer.setFragmentLoaderRetryInterval(300);
    this.dashPlayer.setBandwidthSafetyFactor(0.5);
    this.dashPlayer.setStableBufferTime(2);
    this.dashPlayer.setBufferTimeAtTopQuality(2);
  }

  remove() {
    if (this.dashPlayer) {
      this.dashPlayer.reset()
    }
  }
}

Dash.formats = {
  'application/dash+xml': 'dash'
}

Dash.canPlayType = function (type) {
  if (type in Dash.formats) {
    return 'maybe'
  }

  return ''
}

Dash.canPlaySource = function (srcObj, options) {
  return Dash.canPlayType(srcObj.type)
}

Dash.VERSION = '__VERSION__'

export default Dash
